﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Manage/MasterPage.master" AutoEventWireup="true" CodeFile="ListLinkers.aspx.cs" Inherits="Manage_ListLinkers" %>
<%@ Register Src="~/Manage/CmsMessageBox.ascx" TagPrefix="cms" TagName="MessageBox" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        input.aa
        {
            border: 1px solid #cecece;
            padding: 4px 5px 4px 5px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="body" Runat="Server">
    <script type="text/javascript">
        $(document).ready(function () {
            $('#SearchBar').width($('#Body table.List').width());

            
            //设置所有输入的文本框的样式
            $('input:text').addClass('aa');

            $('#<%=Save.ClientID %>').click(function () {
                var id = 1;
                var msg = '';
                var linkers = [];
                var maxLevel = 0;

                var trs = $('table.List > tbody > tr');
                for (var i = 1; i < trs.size(); i++) {
                    var tr = $(trs[i]);

                    var level = tr.attr('level');
                    var c1 = tr.children('td:eq(0)');
                    var c2 = tr.children('td:eq(1)');
                    var c3 = tr.children('td:eq(2)');
                    var c4 = tr.children('td:eq(3)');

                    var sequence = $(c1.children().children().children().children()[0]).children().val();
                    var name = $(c1.children().children().children().children()[1]).children().val()
                    var url = c2.children().val();
                    var title = c3.children().val();
                    var target = c4.children(':checked').val();

                    linkers[linkers.length] = { 'id': id++,
                        'level': level,
                        'sequence': sequence,
                        'name': name,
                        'url': url,
                        'title': title,
                        'target': target,
                        'parent': 0
                    };
                }

                var levels = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
                $(linkers).each(function (idx, o) {
                    if (o.level != 0) {
                        o.parent = levels[o.level - 1];
                    }
                    levels[o.level] = o.id;

                    var m = '&lt;linker id="' + o.id + '"&gt;';
                    m += '&lt;sequence&gt;' + o.sequence + '&lt;/sequence&gt;';
                    m += '&lt;name&gt;' + o.name + '&lt;/name&gt;';
                    m += '&lt;url&gt;' + o.url + '&lt;/url&gt;';
                    m += '&lt;title&gt;' + o.title + '&lt;/title&gt;';
                    m += '&lt;target&gt;' + o.target + '&lt;/target&gt;';
                    m += '&lt;parent&gt;' + o.parent + '&lt;/parent&gt;';
                    m += '&lt;/linker&gt;';

                    msg += m;
                });

                msg = "&lt;linkers&gt;" + msg + "&lt;/linkers&gt;";

                $('input#<%=LinkerXML.ClientID %>').val(msg);

                return true;
            });
        });
    </script> 
    <cms:MessageBox id="MessageBox" runat="server" />
    <asp:HiddenField ID="CurrentPage" runat="server" Value="1" />
    <div id="SearchBar">
        <table cellpadding="0" cellspacing="0">
            <tr>
                <td style="padding-right: 5px"><asp:Button ID="Save" runat="server" Text="保存导航" onclick="Save_Click" /></td>
                <td><asp:Button ID="Create" runat="server" Text="生成静态" /></td>
            </tr>
        </table>
    </div>
    <div style="clear: both">
        <table class="List" cellspacing="1">
            <tr class="header">
                <!--th style="width:50px">操作</th-->
                <th style="width:300px">导航名称</th>
                <th style="width:250px">URL</th>
                <th style="width:200px">鼠标经过文字</th>
                <th style="width:150px">打开方式</th>
            </tr>

            <%=GenerateTable(null, 0)%>
        </table>
        <asp:HiddenField ID="LinkerXML" runat="server" />
    </div>
</asp:Content>

